using System;
using Microsoft.Practices.CompositeWeb.Web.UI;
using Microsoft.Practices.ObjectBuilder;
using PageFlowQuickstart.Modules.Customers.BusinessEntities;
using PageFlowQuickstart.Modules.Customers.Views;

public partial class Customers_SummaryView : Page, ISummaryView
{
    SummaryViewPresenter _presenter;
    private Customer _customer;

    protected void Page_LoadComplete(object sender, EventArgs e)
    {
        ShowCustomer();
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            _presenter.OnViewInitialized();
        }
        _presenter.OnViewLoaded();
    }

    [CreateNew]
    public SummaryViewPresenter Presenter
    {
		get
		{
			return _presenter;
		}
        set
        {
            _presenter = value;
            _presenter.View = this;
        }
    }

    #region ISummaryView Members

    public Customer Customer
    {
        set { _customer = value; }
    }

    #endregion

    private void ShowCustomer()
    {
        if (_customer == null)
            return;

        _lastNameLabel.Text = _customer.LastName;
        _nameLabel.Text = _customer.Name;
        _idLabel.Text = _customer.Id.ToString();
    }

    protected void ApproveAnotherCustomerButton_Click(object sender, EventArgs e)
    {
        _presenter.OnApproveAnotherCustomer();
    }
}
